<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!-- 官网提供的 axios 在线地址 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<body>


<div id="app">
    <el-container>
        <el-header>Header</el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu
                        default-active="2"
                        class="el-menu-vertical-demo"
                        @open="handleOpen"
                        @close="handleClose"
                        background-color="#545c64"
                        text-color="#fff"
                        active-text-color="#ffd04b">
                    <el-submenu :index="e.pid"  v-for="e in leftMenu">
                        <template slot="title">{{e.pname}}</template>
                        <el-menu-item  :index="child.per_id" v-for="child in e.childPermission" text-color="#fff">
                            <a style="color: white;text-decoration: none"    @click="showContent(child.purl,child.pname)">
                                ● {{child.pname}}
                            </a></el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <!--标签页-->
                <el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab" >
                    <el-tab-pane
                            v-for="(item, index) in editableTabs"
                            :key="item.name"
                            :label="item.title"
                            :name="item.name"
                    >
                        <!--   {{item.content}}-->
                        <iframe :src="item.url"  frameborder="0" width="100%" height="600px;"></iframe>
                    </el-tab-pane>
                </el-tabs>
            </el-main>

        </el-container>
        <el-footer>Footer</el-footer>
    </el-container>
</div>


</body>
<script>
    new Vue({
        el: "#app",
        data: {

            //左侧菜单
            leftMenu:[],
            //标签页 开始
            editableTabsValue: '1',
            editableTabs: [{
                title: '首页',
                name: '1',
                url: '/home.html'
                //content: 'Tab 1 content'
            }],
            tabIndex: 1
        },
        created() {
            this.initPage()
        },
        methods: {
            initPage() {
                axios.post("/Per/AllPer").then(rust => {
                    console.log(rust.data.data)
                    this.leftMenu=rust.data.data
                })
            },
            //显示当前连接的内容
            showContent(url,menuName){
                //alert(url+","+menuName);
                //直接调用添加页签页
                this.addTab(menuName,url);
            },
            //添加标签页
            addTab(targetName,url) { //targetName 页签页名称   url 对应的地址

                let newTabName = ++this.tabIndex + '';
                //获取所有的标签页
                let tabs = this.editableTabs;
                //定义是否已经标签变量
                var  isHaveTab = false;
                //循环所有页签页 判断当前点击标签页名称已经存在
                tabs.forEach((tab, index) => {
                    //如果为true 说明当前点击节点（部门管理），已经存在标签页
                    if(targetName === tab.title){// 判断是否相等  1=='1' 值相等  true   1==='1'  false 类型和值都香港等
                        isHaveTab = true;
                        newTabName =tab.name;
                    }
                });
                //如果不存在 添加一个
                if(!isHaveTab) {
                    this.editableTabs.push({
                        title: targetName,
                        name: newTabName,
                        url: url
                        //content: 'New Tab content'
                    });
                }
                //如果存在，直接让高亮
                this.editableTabsValue = newTabName;
            },
            //移除页签页
            removeTab(targetName) {
                let tabs = this.editableTabs;
                let activeName = this.editableTabsValue;
                if (activeName === targetName) {
                    tabs.forEach((tab, index) => {
                        if (tab.name === targetName) {
                            let nextTab = tabs[index + 1] || tabs[index - 1];
                            if (nextTab) {
                                activeName = nextTab.name;
                            }
                        }
                    });
                }

                this.editableTabsValue = activeName;
                this.editableTabs = tabs.filter(tab => tab.name !== targetName);
            },
        }
    })
</script>
<style>
    .el-header, .el-footer {
        background-color: #B3C0D1;
        color: #333;
        text-align: center;
        line-height: 60px;
    }

    .el-aside {
        background-color: #D3DCE6;
        color: #333;
        text-align: center;
        line-height: 200px;
    }

    .el-main {
        background-color: #E9EEF3;
        color: #333;
        text-align: center;
        line-height: 160px;
    }

    body > .el-container {
        margin-bottom: 40px;
    }

    .el-container:nth-child(5) .el-aside,
    .el-container:nth-child(6) .el-aside {
        line-height: 260px;
    }

    .el-container:nth-child(7) .el-aside {
        line-height: 320px;
    }

    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>

</html>